package com.sheep.spark.service.impl;

import com.sheep.api.bean.ADSBBean;
import com.sheep.api.bean.ADSBResultBean;
import com.sheep.api.spark.SparkCommonDao;
import com.sheep.api.spark.SparkCommonService;
import com.sheep.api.util.Constant;
import com.sheep.api.util.JAXBUtils;
import com.sheep.spark.dao.SparkCommonDaoImpl;
import com.sheep.api.util.ZipUtil;
import org.apache.log4j.Logger;

import java.io.Serializable;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 16-5-25
 * Time: 下午3:37
 * To change this template use File | Settings | File Templates.
 */
public class SparkCommonImpl implements Serializable, SparkCommonService {
    private static final Logger logger = Logger.getLogger(SparkCommonImpl.class);

    private SparkCommonDao dao = new SparkCommonDaoImpl();

    @Override
    public String getADSBDataByCompress(String year, String month, String date, String an, String fi) {
        try {
            ADSBResultBean result = new ADSBResultBean();
            long start = System.currentTimeMillis();
            List<ADSBBean> list = dao.getADSBList(year, month, date, an, fi);
            long end = System.currentTimeMillis();
            result.setRunTime(end - start);
            if (list != null && list.size() > 0) {
                result.setList(list);
                result.setResultCode(Constant.resultCode_HAVEDATA);
            } else {
                result.setResultCode(Constant.resultCode_NODATA);
            }
            return ZipUtil.compress(JAXBUtils.dtoToXmlString(result));
        } catch (Exception e) {
            logger.error(e);
        }
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public List<ADSBBean> getADSBList(String year, String month, String date, String an, String fi) {
        try {
            return dao.getADSBList(year, month, date, an, fi);
        } catch (Exception e) {
            logger.error(e);
        }
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public List<ADSBBean> getADSBListByTime(String year, String month, String date, String an, String fi, double start, double end) {
        try {
            return dao.getADSBListByTime(year, month, date, an, fi, start, end);
        } catch (Exception e) {
            logger.error(e);
        }
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public List<String> getADSBJson(String year, String month, String date, String an, String fi) {
        try {
            return dao.getADSBJson(year, month, date, an, fi);
        } catch (Exception e) {
            logger.error(e);
        }
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public List<ADSBBean> getADSBJsonByTime(String year, String month, String date, String an, String fi, double start, double end) {
        try {
            return dao.getADSBJsonByTime(year, month, date, an, fi, start, end);
        } catch (Exception e) {
            logger.error(e);
        }
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }
}
